home *** CD-ROM | disk | FTP | other *** search
/ JCSM Shareware Collection 1996 September / JCSM Shareware Collection (JCS Distribution) (September 1996).ISO / screenut / barclk41.zip / BCSDK.ZIP / QEXIT.C < prev    next >
C/C++ Source or Header  |  1995-04-01  |  4KB  |  185 lines

  1. /*
  2.     BarClock(tm)
  3.  
  4.     Keyword Extension Sample
  5.  
  6.     Copyright (c) 1994  Patrick Breen
  7.     All rights reserved.
  8.  
  9.     Contact Information:
  10.  
  11.         Atomic Dog Software
  12.         PO Box 523
  13.         Medford, MA 02155
  14.  
  15.         Phone (617) 396-2673
  16.         Fax   (617) 396-5761
  17.  
  18.         Internet:            pbreen@world.std.com
  19.         CompuServe:         70312,743
  20.         America Online:     PBreen
  21. */
  22.  
  23. #include "bchook.h"
  24.  
  25. // Handle to the DLL instance from Libinit.asm
  26. HANDLE LIBINST;
  27. HMENU hMenu;
  28.  
  29. BOOL CALLBACK QExitSetup(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
  30. static BOOL ConfirmExit(void);
  31. static short ButtonAction(void);
  32.  
  33. void cdecl _cexit(void)
  34. {
  35. }
  36.  
  37. // Standard library initialization
  38. int FAR PASCAL LibMain(HINSTANCE hInstance, WORD a, WORD b, LPSTR c)
  39. {
  40.     LIBINST = hInstance;
  41.     return 1;
  42. }
  43.  
  44. // Standard library exit
  45. int FAR PASCAL WEP(int a)
  46. {
  47.     return TRUE;
  48. }
  49.  
  50. // Standard version number return
  51. DWORD FAR _export BCHookVersion(DWORD FAR *pSig)
  52. {
  53.     (*pSig) = 0x04534441L;        // 'ADS' (in reverse) x4
  54.     return HOOKVERSION;
  55. }
  56.  
  57. // Return the number of buttons we support
  58. BYTE FAR _export BCBtnCount(void)
  59. {
  60.     // We support 1 buttons
  61.     return 1;
  62. }
  63.  
  64. // Return the label for the button
  65. void FAR _export BCBtnLabel(BYTE btnId, LPSTR pLabelBuf)
  66. {
  67.     // Copy appropriate label into buffer
  68.     lstrcpy(pLabelBuf, "Quick Exit");
  69. }
  70.  
  71. // Return a menu that should be displayed
  72. // when the specified button is clicked -
  73. // this function is called just prior to
  74. // display of the menu
  75. HMENU FAR _export BCBtnMenu(BYTE btnId, BOOL bLeft)
  76. {
  77.     if (!bLeft) {
  78.  
  79.         // Create a popup menu (if a resource
  80.         // menu is used, be sure to call the
  81.         // function GetSubMenu to get the
  82.         // proper popup menu handle to display
  83.         //
  84.         // e.g.
  85.         //
  86.         // hMenu = LoadMenu(hInstance, MAKEINTRESOURCE(id));
  87.         // hPopup = GetSubMenu(hMenu, 0);
  88.  
  89.         // We will create our menu
  90.         hMenu = CreatePopupMenu();
  91.  
  92.         // Add to the menu
  93.         AppendMenu(hMenu, 0, 1, "Exit Windows");
  94.         AppendMenu(hMenu, 0, 2, "Restart Windows");
  95.         AppendMenu(hMenu, 0, 3, "Reboot");
  96.         AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
  97.         AppendMenu(hMenu, 0, 4, "Setup...");
  98.     }
  99.  
  100.     return hMenu;
  101. }
  102.  
  103. // Handle a button select
  104. void FAR _export BCBtnClick(BYTE btnId, BOOL bLeft)
  105. {
  106.     // Default to exit windows
  107.     BCBtnMenuSelect(btnId, 1 + ButtonAction());
  108. }
  109.  
  110. // Handle a menu selection
  111. void FAR _export BCBtnMenuSelect(BYTE btnId, short itemId)
  112. {
  113.     // Clean up menu
  114.     DestroyMenu(hMenu);
  115.     hMenu = 0;
  116.  
  117.     // Check for confirmation
  118.     if ((itemId > 0) && (itemId < 4) && ConfirmExit()) {
  119.  
  120.         if (MessageBox((HWND) 0,
  121.                     (itemId == 1)? "OK to end Windows session?":
  122.                     (itemId == 2)? "OK to restart Windows?":
  123.                                 "OK to reboot system?",
  124.                     "Quick Exit",
  125.                     MB_ICONSTOP | MB_YESNO) == IDNO)
  126.             return;
  127.     }
  128.  
  129.     switch (itemId) {
  130.  
  131.         case 1: ExitWindows(MAKELONG(0, 0), 0); break;
  132.         case 2: ExitWindows(MAKELONG(EW_RESTARTWINDOWS, 0), 0); break;
  133.         case 3: ExitWindows(MAKELONG(EW_REBOOTSYSTEM, 0), 0); break;
  134.         case 4: DialogBox(LIBINST, MAKEINTRESOURCE(400), (HWND) 0, QExitSetup); break;
  135.     }
  136.  
  137.     return;
  138. }
  139.  
  140. static BOOL ConfirmExit(void)
  141. {
  142.     return GetPrivateProfileInt("QExit", "Confirm", 1, "BARCLOCK.INI");
  143. }
  144.  
  145. static short ButtonAction(void)
  146. {
  147.     return GetPrivateProfileInt("QExit", "BtnAction", 1, "BARCLOCK.INI");
  148. }
  149.  
  150. BOOL CALLBACK QExitSetup(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  151. {
  152.     // If confirmed
  153.     if (msg == WM_INITDIALOG) {
  154.  
  155.         // Set the default values
  156.         CheckDlgButton(hwndDlg, (ButtonAction())? 101:100, TRUE);
  157.         CheckDlgButton(hwndDlg, 102, ConfirmExit());
  158.  
  159.     } else if (msg == WM_COMMAND) {
  160.  
  161.         switch (wParam) {
  162.  
  163.             case IDOK:
  164.                 // Update profile settings
  165.                 WritePrivateProfileString("QExit", "BtnAction",
  166.                                      (IsDlgButtonChecked(hwndDlg, 101))? "1":"0",
  167.                                      "BARCLOCK.INI");
  168.  
  169.                 WritePrivateProfileString("QExit", "Confirm",
  170.                                      (IsDlgButtonChecked(hwndDlg, 102))? "1":"0",
  171.                                      "BARCLOCK.INI");
  172.  
  173.  
  174.             case IDCANCEL:
  175.                 // Any command message causes this
  176.                 // dialog to go awaw
  177.                 EndDialog(hwndDlg, wParam);
  178.                 return TRUE;
  179.         }
  180.     }
  181.  
  182.     return (msg == WM_INITDIALOG);
  183. }
  184.  
  185.